package com.hlf.modules.merchant.order.service.impl;

import com.hlf.modules.merchant.goods.entity.Goods;
import com.hlf.modules.merchant.goods.mapper.GoodsMapper;
import com.hlf.modules.merchant.order.entity.OrderDetail;
import com.hlf.modules.merchant.order.mapper.OrderDetailMapper;
import com.hlf.modules.merchant.order.service.OrderDetailService;
import com.hlf.modules.sys.entity.FileVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/9/30.
 */
@Service("OrderDetailService")
public class OrderDetailServiceImpl implements OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int insertSelective(OrderDetail orderDetail) {
        return orderDetailMapper.insertSelective(orderDetail);
    }

    @Override
    public List<OrderDetail> selectDapthByOrderId(long id) {
        List<OrderDetail> orderDetails = orderDetailMapper.selectDapthByOrderId(id);
        for (OrderDetail orderDetail : orderDetails) {
            String goodsId = orderDetail.getGoodsId();
            Goods goods = goodsMapper.queryObject(goodsId);
            if (goods != null) {
                orderDetail.setGoodsName(goods.getName());
                orderDetail.setOnePrice(goods.getSellPrice());
            }
            List<FileVO> imgList = orderDetail.getImgList();
            if (imgList.size() == 0) {
                continue;
            }
            FileVO fileVO = imgList.get(0);
            orderDetail.setUrl(fileVO.getFilSerPath());
        }
        return orderDetails;
    }
}
